//
//  MoreAnchorVC.m
//  MarianasTrench
//
//  Created by 付建国 on 16/3/22.
//  Copyright © 2016年 王爵. All rights reserved.
//

#import "MoreAnchorVC.h"
#import "JGRankingTableViewCell.h"
#import "ListModel.h"
#import "JGAnchorDigestVC.h"

@interface MoreAnchorVC ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *backTableV;

@property (nonatomic, strong) NSMutableArray *modelArr;

@property (nonatomic, strong) NSString *path;

@end

@implementation MoreAnchorVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    self.modelArr = [NSMutableArray array];
    self.navigationItem.title = _myTitle;
    
    
    [self dataHander];
    [self createView];
    
}
#pragma mark - 创建视图
- (void)createView{
    
    self.backTableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HETGHT) style:UITableViewStylePlain];
    [self.view addSubview:_backTableV];
    self.backTableV.delegate = self;
    self.backTableV.dataSource = self;
    self.backTableV.rowHeight = 90;
    
    // 注册cell
    [self.backTableV registerClass:[JGRankingTableViewCell class] forCellReuseIdentifier:@"JGRankingTableViewCell"];

}
#pragma mark - 协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.modelArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    JGRankingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JGRankingTableViewCell"];
    
    ListModel *model = self.modelArr[indexPath.row];
    
    cell.model = model;
    
    return cell;
}
// cell的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    JGAnchorDigestVC *anchorDigestVC = [[JGAnchorDigestVC alloc] init];
    
    ListModel *model = [[ListModel alloc] init];
    model = self.modelArr[indexPath.row];
    
    anchorDigestVC.uid = model.uid;
    anchorDigestVC.title = model.title;
    anchorDigestVC.currentPage = model.currentPage;

    [self.navigationController pushViewController:anchorDigestVC animated:YES];
}
#pragma mark - 数据解析
- (void)dataHander{
    if ([_name isEqualToString:@"hot"]) {
        self.path = [NSString stringWithFormat:@"http://mobile.ximalaya.com/m/explore_user_list?category_name=all&condition=%@&device=android&page=1&per_page=20", _name];
    }else{
        self.path = [NSString stringWithFormat:@"http://mobile.ximalaya.com/m/explore_user_list?category_name=%@&condition=hot&device=android&page=1&per_page=20", _name];
    }
    [APPTools GETWithURL:_path par:nil success:^(id responseObject) {
        
        NSArray *arr = [responseObject objectForKey:@"list"];
        
        self.modelArr = [ListModel modelHandleWithArray:arr];
        
        [self.backTableV reloadData];
        
    } filed:^(NSError *error) {
        
    }];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
